package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SyArticle;
import com.ruoyi.system.service.ISyArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 技术文章管理Controller
 * @date 2022-11-05
 */
@RestController
@RequestMapping("/api/system/syarticle")
public class SyArticleController extends BaseController
{
    @Autowired
    private ISyArticleService syArticleService;

    /**
     * 查询技术文章管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:syarticle:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyArticle syArticle)
    {
        startPage();
        List<SyArticle> list = syArticleService.selectSyArticleList(syArticle);
        return getDataTable(list);
    }

    /**
     * 导出技术文章管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:syarticle:export')")
    @Log(title = "技术文章管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyArticle syArticle)
    {
        List<SyArticle> list = syArticleService.selectSyArticleList(syArticle);
        ExcelUtil<SyArticle> util = new ExcelUtil<SyArticle>(SyArticle.class);
        util.exportExcel(response, list, "技术文章管理数据");
    }

    /**
     * 获取技术文章管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:syarticle:query')")
    @GetMapping(value = "/{aid}")
    public AjaxResult getInfo(@PathVariable("aid") Long aid)
    {
        return AjaxResult.success(syArticleService.selectSyArticleByAid(aid));
    }

    /**
     * 新增技术文章管理
     */
    @PreAuthorize("@ss.hasPermi('system:syarticle:add')")
    @Log(title = "技术文章管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyArticle syArticle)
    {
        return toAjax(syArticleService.insertSyArticle(syArticle));
    }

    /**
     * 修改技术文章管理
     */
    @PreAuthorize("@ss.hasPermi('system:syarticle:edit')")
    @Log(title = "技术文章管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyArticle syArticle)
    {
        return toAjax(syArticleService.updateSyArticle(syArticle));
    }

    /**
     * 删除技术文章管理
     */
    @PreAuthorize("@ss.hasPermi('system:syarticle:remove')")
    @Log(title = "技术文章管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{aids}")
    public AjaxResult remove(@PathVariable Long[] aids)
    {
        return toAjax(syArticleService.deleteSyArticleByAids(aids));
    }
}
